package com.student_exam_system.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.student_exam_system.pojo.Score;
import com.student_exam_system.service.ScoreService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 86134
 */
@Controller
@RequestMapping("/score")
public class ScoreController {
    @Resource
    private ScoreService scoreService;

    @PreAuthorize("hasAuthority('teacher')")
    @RequestMapping("/showScore/{choice}/{classId}/{paperId}")
    @ResponseBody
    public String showScore(@PathVariable int choice, @PathVariable int classId, @PathVariable int paperId){
        List<Score> scores = scoreService.showScore(choice, classId, paperId);
        ObjectMapper objectMapper = new ObjectMapper();
        String json=null;
        try {
            json = objectMapper.writeValueAsString(scores);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
}
